 <#include "${re.contextPath}/mobile/core/head.ftl"/>
 
 <script type="text/javascript"> 


// // 	$.getJSON('${re.contextPath}/mobile/tologin', {username:'xx', password:'yy'}, function(data) {
// // 			debugger
// // 		console.log(data);
// // 		return data;
// // 	});

// // 	var tmp=[];

// $(document).ready(function(){debugger
// 	<#if open??>
// 		$("#my-alert").modal('open'); 
// 	</#if>
		
//   $("form").submit(function(e){
	  
// // 	  var b =true;
// // 		 $.ajax({
// // 				type : 'POST',
// // 				url : '${re.contextPath}/mobile/checklogin',
// // 				async : false,
// // 				dataType : "json",
// // 				data: {username:$('#doc-vld-name-2-0').val(), password:$('#doc-vld-pwd-1-0').val()},
// // 				success : function(data) {debugger
// // 					console.log(data); // 问题：值如何传递到外面去。
// // 					if(!data.success){
// // 						b = false;
// // 						console.log("登陆信息错误");
// // 						$("#my-alert").modal('open'); 
// // 					}
// // 				},
// // 				error : function(a, b, c) {
// // 					console.log('error');
// // 					console.log(a);
// // 					console.log(b);
// // 					console.log(c);
// // 				}

// // 			});
// // 		 return b;
//   });
// });

	
</script>
 
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，Amaze UI 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->

<#include "${re.contextPath}/mobile/admin/left.ftl"/> 

  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">个人资料</strong> / <small>Personal information</small></div>
      </div>

      <hr/>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-4 am-u-md-push-8">
          <div class="am-panel am-panel-default">
            <div class="am-panel-bd">
              <div class="am-g">
                <div class="am-u-md-4">
                  <img id="chooseImage" class="am-img-circle am-img-thumbnail" src="${re.contextPath}/img?name=${user.photo}" alt=""/>
                </div>
                <div class="am-u-md-8">
                  <p>你可以使用<a href="#">gravatar.com</a>提供的头像或者使用本地上传头像。 </p>
                  <form id="fileFrom" class="am-form">
                    <div class="am-form-group">
                      <input type="file" id="user-pic" name="file">
                      <p class="am-form-help">请选择要上传的文件...</p>
                      <button id="saveImg" type="button" class="am-btn am-btn-primary am-btn-xs">保存</button>
                    </div>
                  </form>
                </div>
              </div>
            </div>
          </div>

          <div class="am-panel am-panel-default">
            <div class="am-panel-bd">
              <div class="user-info">
                <p>等级信息</p>
                <div class="am-progress am-progress-sm">
                  <div class="am-progress-bar" style="width: 60%"></div>
                </div>
                <p class="user-info-order">当前等级：<strong>LV8</strong> 活跃天数：<strong>587</strong> 距离下一级别：<strong>160</strong></p>
              </div>
              <div class="user-info">
                <p>信用信息</p>
                <div class="am-progress am-progress-sm">
                  <div class="am-progress-bar am-progress-bar-success" style="width: 80%"></div>
                </div>
                <p class="user-info-order">信用等级：正常当前 信用积分：<strong>80</strong></p>
              </div>
            </div>
          </div>

        </div>

        <div class="am-u-sm-12 am-u-md-8 am-u-md-pull-4">
          <form action="${re.contextPath }/admin/user/save"  method="post" class="am-form am-form-horizontal">
            <div class="am-form-group">
              <label for="user-name" class="am-u-sm-3 am-form-label">姓名 / Name</label>
              <div class="am-u-sm-9">
              <input type="hidden" name="uid" value="${user.uid }">
                <input type="text" id="user-name" name="username" value="${user.username}" placeholder="姓名 / Name">
                <small>输入你的名字，让我们记住你。</small>
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-email" class="am-u-sm-3 am-form-label">电子邮件 / Email</label>
              <div class="am-u-sm-9">
                <input type="email" id="user-email" name="email" value="${user.email}" placeholder="输入你的电子邮件 / Email">
                <small>邮箱你懂得...</small>
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-phone" class="am-u-sm-3 am-form-label">电话 / Telephone</label>
              <div class="am-u-sm-9">
                <input type="number" id="user-phone" name="phone" value="#{user.phone}" placeholder="输入你的电话号码 / Telephone">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-QQ" class="am-u-sm-3 am-form-label">QQ</label>
              <div class="am-u-sm-9">
                <input type="number" pattern="[0-9]*" name="qq" value="${user.qq}" id="user-QQ" placeholder="输入你的QQ号码">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-weibo" class="am-u-sm-3 am-form-label">微博 / Twitter</label>
              <div class="am-u-sm-9">
                <input type="text" id="user-weibo"  name="twitter" value="${user.twitter}" placeholder="输入你的微博 / Twitter">
              </div>
            </div>

            <div class="am-form-group">
              <label for="user-intro" class="am-u-sm-3 am-form-label">简介 / Intro</label>
              <div class="am-u-sm-9">
                <textarea class="" rows="5" id="user-intro" name="intro"  placeholder="输入个人简介">${user.intro}</textarea>
                <small>250字以内写出你的一生...</small>
              </div>
            </div>

            <div class="am-form-group">
              <div class="am-u-sm-9 am-u-sm-push-3">
                <button id="save"  type="submit" class="am-btn am-btn-primary">保存修改</button>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>

    <footer class="admin-content-footer">
      <hr>
      <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>

  </div>
  <!-- content end -->

</div>

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<footer>
  <hr>
  <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
</footer>


</body>
<script>  
    $("#saveImg").on("click",function () {
  
	var formData = new FormData();
		var name = $("#user-pic").val();
		formData.append("file", $("#fileFrom")[0][0].files[0]);
		formData.append("name", name);
		$.ajax({
			url : "${re.contextPath}/admin/user/saveImg",
			type : 'POST',
			data : formData,
			// 告诉jQuery不要去处理发送的数据
			processData : false,
			// 告诉jQuery不要去设置Content-Type请求头
			contentType : false,
			beforeSend : function() {
				console.log("正在进行，请稍候");
			},
			success : function(responseStr) {
				if (responseStr.status === 0) {
					console.log("成功" + responseStr);
				} else {
					console.log("失败");
				}
			},
			error : function(responseStr) {
				console.log("error");
			}
		});
	});
    
    $('#user-pic').on('change',function(){  
        var filePath = $(this).val(),         //获取到input的value，里面是文件的路径  
            fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),  
            src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式  
              
        // 检查是否是图片  
        if( !fileFormat.match(/.png|.jpg|.jpeg/) ) {  
            error_prompt_alert('上传错误,文件格式必须为：png/jpg/jpeg');  
            return;    
        }  
    
        $('#chooseImage').attr('src',src);  
	});  
</script>  

</html>
